const express = require('express');
const noteRouter = require('./routes/noteRouter');
const noteApiRouter = require('./routes/noteApiRouter');
const loginRouter = require('./routes/loginRouter');
const bodyParser = require('body-parser'); //等同于express.urlencoded
const ejs = require('ejs');
// const path= require('path'); //未解构
const {resolve} = require('path'); //处理路径模块

const app = express();
// 配置获取请求体中间件
app.use(bodyParser.urlencoded({extended:false}))
// 配置静态资源文件目录
// app.use(express.static(__dirname+'/public'));  字符串拼接
// app.use(express.static(path.resolve(__dirname,'./public')));  未解构使用版
app.use(express.static(resolve(__dirname,'./public'))); //解构使用版 //等同于 __dirname+'/views'
app.set('views',resolve(__dirname,'./views'));
app.engine('html',ejs.renderFile);


app.use(loginRouter)
// 调用页面router
app.use(noteRouter)
// 调用note接口router
app.use(noteApiRouter)

app.listen(80,()=>{
    console.log('启动成功');
})

